package com.wlyuan.open.scanner.utils.enums;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum CarrierSubjectTypeEnum implements NamedValue<Integer> {
    COMPANY(0, "企业"), DRIVER(1, "司机");

    private final Integer value;
    private final String name;

    private static final Map<Integer, CarrierSubjectTypeEnum> MAP = new NamedValueMap<>(CarrierSubjectTypeEnum.class);

    public static CarrierSubjectTypeEnum fromValue(Integer value) {
        return Optional.ofNullable(value).map(CarrierSubjectTypeEnum::get).orElse(null);
    }

    private static CarrierSubjectTypeEnum get(Integer val) {
        return Optional.ofNullable(MAP.get(val)).orElse(CarrierSubjectTypeEnum.COMPANY);
    }
}
